package com.pxt.demo;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.widget.EditText;
import android.widget.TextClock;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Demo2Activity extends AppCompatActivity implements TextWatcher {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo2);
        findViewById(R.id.editPinyins).requestFocus();
        ((EditText) findViewById(R.id.editPinyins)).addTextChangedListener(this);
        ((EditText) findViewById(R.id.editPinyins)).setKeyListener(DigitsKeyListener.getInstance("abcdefghijklmnopqrstuvwxyz"));
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void afterTextChanged(Editable s) {
//        Pattern pattern = Pattern.compile("[a-zA-Z]+");
//        Matcher matcher = pattern.matcher(s.toString());
//        if (!matcher.matches()) {
//            Toast.makeText(this, "请输入英文字母A-Z", Toast.LENGTH_SHORT).show();
//        }
        ((TextView) findViewById(R.id.split)).setText(PinyinUtil.getInstance().splitPinyin(s.toString().trim()));
    }
}
